﻿using FwtXnaGame3.Common;
using GpgCore.CityItems;
using GpgCore.GameWorld;
using GpgCore.MapItems;
using GpgCore.Products;

namespace GpgCore.Corporations
{
    public class CityOffice
    {
        public Corporation OwnCorp;
        public City City;
        public Warehouse Warehouse;
        public double Money; //Money always lay in legal currency in city office
        public SmartList<Factory> Factories;
        public SmartList<Mine> Mines;
        public SmartList<Farm> Farms;
        public SmartDictionary<ProductType, Shop> Shops; 

        public double ExtractMoney(double count)
        {
            if (Money < count)
                count = Money;

            Money -= count;
            return count;
        }

        public CityOffice(Corporation ownCorp, City city)
        {
            OwnCorp = ownCorp;
            City = city;
            Warehouse = new Warehouse();
            OwnCorp.CityOffices.Insert(city, this);
            City.CityOffices.Insert(ownCorp, this);

            Factories = new SmartList<Factory>();
            Mines = new SmartList<Mine>();
            Farms = new SmartList<Farm>();
            Shops = new SmartDictionary<ProductType, Shop>();
        }

        public void Morning()
        {
            foreach (var mine in Mines)
                mine.StartNextTurn();
            foreach (var farm in Farms)
                farm.StartNextTurn();
            foreach (var factory in Factories)
                factory.StartNextTurn();
            foreach (var shop in Shops)
                shop.Value.Morning();
        }
        public void Evening()
        {
            foreach (var mine in Mines)
                mine.EndNextTurn();
            foreach (var farm in Farms)
                farm.EndNextTurn();
            foreach (var factory in Factories)
                factory.EndNextTurn();
            foreach (var shop in Shops)
                shop.Value.Evening();
        }
    }
}
